﻿using Microsoft.Graphics.Canvas;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Graphics.Imaging;
using Windows.Storage;
using Windows.Storage.FileProperties;
using Windows.Storage.Streams;

namespace 纸片人.win2dEffectControl.DataClass
{
    public class CanvasBitmapData : EffectData
    {
        /// <summary>
        /// 源图像
        /// </summary>
        public SoftwareBitmap Bitmap { get; set; }
        /// <summary>
        /// 压缩图像
        /// </summary>
        private SoftwareBitmap compressionBitmap { get; set; }

        private CanvasDevice device = CanvasDevice.GetSharedDevice();

        private CanvasBitmap canvasBitmap;

        public override ICanvasImage GetEffect(CanvasDevice device, bool compression)
        {

            if (canvasBitmap == null)
                return null;
            return canvasBitmap;
        }

        /// <summary>
        /// 将文件转换为软件位图
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public async Task FileToSoftwareBitmap(StorageFile file)
        {
            using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read))
            {
                canvasBitmap =await CanvasBitmap.LoadAsync(device, stream);
                Size= OriginalSize = canvasBitmap.Size;
                //告诉输出队列我有更改
                SetIsChanges();
            }
        }




    }
}
